#!/usr/bin/env python
# coding=utf-8
from fileshare.extensions import db
from fileshare import create_app
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand
import os
from dotenv import load_dotenv

# 加载环境变量
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
if os.path.exists(dotenv_path):
    load_dotenv(dotenv_path)


app = create_app('production')
manager = Manager(app)
# 绑定app和db
migrate = Migrate(app, db)


def make_shell_context():
    return dict(app=app, db=db)


manager.add_command("shell", Shell(make_context=make_shell_context))
# 把MigrateCommand命令添加到manager中
manager.add_command("db", MigrateCommand)

if __name__ == '__main__':
    '''
    使用方法
    python manage.py db init
    python manage.py db migrate
    python manage.py db upgrade
    '''
    manager.run()
